package com.blog.mapper;

import com.blog.pojo.Hobby;
import com.blog.pojo.Tag;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface HobbyMapper {

    /**
     * 查看用户的兴趣标签
     * @param userId 用户id
     * @return 标签列表
     */
    @Select("select t.* from tag t join hobby h on t.id = h.tag_id " +
            "where h.user_id = #{userId}")
    List<Tag> listByUserId(Integer userId);

    /**
     * 添加用户兴趣标签
     * @param hobby 兴趣实体类
     */
    @Insert("insert into hobby (user_id, tag_id) values (#{userId}, #{tagId})")
    void insert(Hobby hobby);

    /**
     * 删除用户兴趣标签
     * @param userId 用户id
     * @param tagId 标签id
     */
    @Delete("delete from hobby where user_id = #{userId} and tag_id = #{tagId}")
    void delete(Integer userId, Integer tagId);

    /**
     * 查找兴趣表中是否有响应表项
     * @param userId 用户id
     * @param tagId 标签id
     * @return 相应表项个数
     */
    @Select("select count(*) from hobby where user_id = #{userId} and tag_id = #{tagId}")
    Integer find(Integer userId, Integer tagId);

}
